package com.kylin.shared.enums;

import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.springframework.util.CollectionUtils;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * 购买模式
 * @author Damon S.
 * @version v1.0.1
 * @date 2020年05月30日 10:58
 */
@Getter
@RequiredArgsConstructor
public enum BuyModeEnum {
    /**营销策略状态: -1非法值，0正常购买，1营销**/
    NA(-1),
    GENERAL(0),
    MARKETING(1);
    
    private final int code;
    
    public static BuyModeEnum parse(int code) {
        List<BuyModeEnum> filteredStates =
                Arrays.stream(BuyModeEnum.values())
                        .filter(state -> Objects.equals(state.getCode(), code))
                        .collect(Collectors.toList());
        return CollectionUtils.isEmpty(filteredStates) ? NA : filteredStates.get(0);
    }
}
